import Flutter
import UIKit
 
public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
  static fileprivate var channel: FlutterMethodChannel!
 
    public static func register(with registry: FlutterPluginRegistry) {
        let pluginInstance = SwiftFlutterPlugin()
//        registry.register(pluginInstance, with: SwiftFlutterPlugin.self)
  }
    
    public func onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
      // 设置通道，处理方法调用等
    }
    
    public func onDetachedFromEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
      // 插件分离时的清理工作
    }
    
//  public static func register(with controller : FlutterViewController) {
////    channel = FlutterMethodChannel(name: "sing.top/rth", binaryMessenger: registrar.messenger())
////    let instance = SwiftFlutterPlugin()
////    registrar.addMethodCallDelegate(instance, channel: channel!)
//
//    let bridgeChannel = FlutterMethodChannel(name: "sing.top/rth", binaryMessenger: controller.binaryMessenger)
//    bridgeChannel.setMethodCallHandler { (call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
//
//        if (call.method == "getNetParams") {
//           let network = "wifi"
//           let model = "苹果14"
//           let version = "1.0.4"
//           let device_id = "19231241241231"
//           result("?os=1&network=\(network)&model=\(model)&version=\(version)&device_id=\(device_id)&device=iOS")
//
////           result(swiftBridge.getNetParams(str: call.arguments as! String))
//       } else if (call.method == "loadAd") { // 加载广告
//           let adController = AdController()
//           adController.modalPresentationStyle = .fullScreen
//
//           if let viewController = UIApplication.shared.keyWindow?.rootViewController {
//               viewController.present(adController, animated: true, completion: nil)
//           }
//
////            bridgeChannel.invokeMethod("loadAdOver", arguments: "200") { (result) in
////
////            }
//       } else {
//           result(FlutterMethodNotImplemented)
//       }
//    }
//  }
    
    
//  public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
//    if call.method == "navigateToNewPage" {
//
//    } else {
//      result(FlutterMethodNotImplemented)
//    }
//  }
//
//  private func navigateToNewPage(result: @escaping FlutterResult) {
//    let viewController = UIApplication.shared.delegate?.window??.rootViewController
//    let newViewController = NewViewController() // 假设有这样一个ViewController
//
//    // Push the new view controller or present it modally based on your app's navigation structure.
//    viewController?.navigationController?.pushViewController(newViewController, animated: true)
//
//    // When the new page is done, call the result with whatever data you want to send back to Flutter.
//    newViewController.completion = { [weak self] in
//      self?.channel.invokeMethod("pageComplete", arguments: nil)
//      result(true)
//    }
//  }
}
